<!-- Modal -->
<div class="modal fade" id="connexionModal" tabindex="-1" role="dialog" aria-labelledby="connexionModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h3 class="modal-title" id="connexionModalLabel">Connexion</h3>
      </div>
      <div class="modal-body">
         <form>
            <div class="form-group">
              <label for="mailConnexion">Adresse mail</label>
              <input type="email" class="form-control" id="mailConnexion" placeholder="Saisir le mail">
            </div>
            <div class="form-group">
              <label for="passwordConnexion">Mot de passe</label>
              <input type="password" class="form-control" id="passwordConnexion" placeholder="Mot de passe">
            </div>
        </form>
      <div id="msgErreurConnexion" class="alert alert-danger hidden" role="alert"></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
        <button type="button" class="btn btn-primary" id="buttonConnexion">Connexion</button>
      </div>
    </div>
  </div>
</div>
<script>
    $(document).ready(function(){
        var button,retourPopupName;
        
        $('#connexionModal').on('show.bs.modal', function (event) {
            button = $(event.relatedTarget); // Button that triggered the modal
            retourPopupName = button.data('retour-popup');
        });
        $('#connexionModal').on('hidden.bs.modal', function (event) {
            hide($("#msgErreurConnexion"));
        });
        
        $("#buttonConnexion").click(function(){
        $.ajax({
                    type: "POST",
                    url: "<?php echo $BASE_URL; ?>clientController/ajaxConnexion",
                    data: { mail: $("#mailConnexion").val(), passwordConnexion: $("#passwordConnexion").val() },
                    dataType: "json"
                }).done(function( data ) {
                    if(data.mail){
                        hide($("#ongletConnexion"));
                        hide($("#ongletInscription"));                        
                        show($("#ongletDeconnexion"));
                        $("#spanUser").html(' '+data.mail);
                        showInfoUser('<?php echo $BASE_URL; ?>');
                        $('#connexionModal').modal('hide');                       
                        setTimeout(function(){
                            $('#'+retourPopupName).modal('show');
                        }, 500);
                    }else if(data.codeErreur==1){
                        show($("#msgErreurConnexion") );
                        $("#msgErreurConnexion").html("L'identifiant ou le mot de passe saisi sont invalides");                    
                    }
                });
            });
   });
       
</script>